package cn.lidar.controller;

import cn.lidar.entity.SearchMessage;
import cn.lidar.interfaces.ControlGetPicDataService;
import cn.lidar.interfaces.ControlSearchService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("control")
public class ControlController {
  private final ControlSearchService controlSearch;
  private final ControlGetPicDataService controlGetPicData;

  public ControlController(ControlSearchService controlSearch, ControlGetPicDataService controlGetPicData) {
    this.controlSearch = controlSearch;
    this.controlGetPicData = controlGetPicData;
  }

  @RequestMapping("search")
  public List<String> search(@RequestBody SearchMessage message) {
    if (message.getDateRange().size() != 2) {
      return new ArrayList<>();
    }
    return controlSearch.search(message.getSiteName(), message.getDateRange().get(0), message.getDateRange().get(1));
  }

  @RequestMapping("getPicData")
  public List<String> getPicData(@RequestBody String currentFileName) {
//        System.out.println(currentFileName);
    return controlGetPicData.getPicData(currentFileName);
  }
}
